{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Title: #Statistics from a Large Sample"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Difficulty: #Medium"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Category Title: #Algorithms"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Tag Slug: #array #math #probability-and-statistics"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Name Translated: #数组 #数学 #概率与统计"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solution Name: sampleStats"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Title: #大样本统计"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Content:\n",
    "<p>我们对&nbsp;<code>0</code>&nbsp;到&nbsp;<code>255</code>&nbsp;之间的整数进行采样，并将结果存储在数组&nbsp;<code>count</code>&nbsp;中：<code>count[k]</code>&nbsp;就是整数&nbsp;<code>k</code> 在样本中出现的次数。</p>\n",
    "\n",
    "<p>计算以下统计数据:</p>\n",
    "\n",
    "<ul>\n",
    "\t<li><code>minimum</code>&nbsp;：样本中的最小元素。</li>\n",
    "\t<li><code>maximum</code>&nbsp;：样品中的最大元素。</li>\n",
    "\t<li><code>mean</code>&nbsp;：样本的平均值，计算为所有元素的总和除以元素总数。</li>\n",
    "\t<li><code>median</code>&nbsp;：\n",
    "\t<ul>\n",
    "\t\t<li>如果样本的元素个数是奇数，那么一旦样本排序后，中位数 <code>median</code> 就是中间的元素。</li>\n",
    "\t\t<li>如果样本中有偶数个元素，那么中位数<code>median</code> 就是样本排序后中间两个元素的平均值。</li>\n",
    "\t</ul>\n",
    "\t</li>\n",
    "\t<li><code>mode</code>&nbsp;：样本中出现次数最多的数字。保众数是 <strong>唯一</strong> 的。</li>\n",
    "</ul>\n",
    "\n",
    "<p>以浮点数数组的形式返回样本的统计信息<em>&nbsp;</em><code>[minimum, maximum, mean, median, mode]</code>&nbsp;。与真实答案误差在<em>&nbsp;</em><code>10<sup>-5</sup></code><em>&nbsp;</em>内的答案都可以通过。</p>\n",
    "\n",
    "<p>&nbsp;</p>\n",
    "\n",
    "<p><strong>示例 1：</strong></p>\n",
    "\n",
    "<pre>\n",
    "<strong>输入：</strong>count = [0,1,3,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]\n",
    "<strong>输出：</strong>[1.00000,3.00000,2.37500,2.50000,3.00000]\n",
    "<strong>解释：</strong>用count表示的样本为[1,2,2,2,3,3,3,3]。\n",
    "最小值和最大值分别为1和3。\n",
    "均值是(1+2+2+2+3+3+3+3) / 8 = 19 / 8 = 2.375。\n",
    "因为样本的大小是偶数，所以中位数是中间两个元素2和3的平均值，也就是2.5。\n",
    "众数为3，因为它在样本中出现的次数最多。</pre>\n",
    "\n",
    "<p><strong>示例 2：</strong></p>\n",
    "\n",
    "<pre>\n",
    "<strong>输入：</strong>count = [0,4,3,2,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]\n",
    "<strong>输出：</strong>[1.00000,4.00000,2.18182,2.00000,1.00000]\n",
    "<strong>解释：</strong>用count表示的样本为[1,1,1,1,2,2,3,3,3,4,4]。\n",
    "最小值为1，最大值为4。\n",
    "平均数是(1+1+1+1+2+2+2+3+3+4+4)/ 11 = 24 / 11 = 2.18181818…(为了显示，输出显示了整数2.18182)。\n",
    "因为样本的大小是奇数，所以中值是中间元素2。\n",
    "众数为1，因为它在样本中出现的次数最多。\n",
    "</pre>\n",
    "\n",
    "<p>&nbsp;</p>\n",
    "\n",
    "<p><strong>提示：</strong></p>\n",
    "\n",
    "<ul>\n",
    "\t<li><code>count.length == 256</code></li>\n",
    "\t<li><code>0 &lt;= count[i] &lt;= 10<sup>9</sup></code></li>\n",
    "\t<li><code>1 &lt;= sum(count) &lt;= 10<sup>9</sup></code></li>\n",
    "\t<li>&nbsp;<code>count</code>&nbsp;的众数是 <strong>唯一</strong> 的</li>\n",
    "</ul>\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Description: [statistics-from-a-large-sample](https://leetcode.cn/problems/statistics-from-a-large-sample/description/)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solutions: [statistics-from-a-large-sample](https://leetcode.cn/problems/statistics-from-a-large-sample/solutions/)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "test_cases = ['[0,1,3,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]', '[0,4,3,2,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sampleStats(self, count: List[int]) -> List[float]:\n",
    "        n = len(count)\n",
    "        total = sum(count)\n",
    "        mean = 0.0\n",
    "        median = 0.0\n",
    "        min_num = 256\n",
    "        max_num = 0\n",
    "        mode = 0\n",
    "\n",
    "        left = (total + 1) // 2\n",
    "        right = (total + 2) // 2\n",
    "        cnt = 0\n",
    "        max_freq = 0\n",
    "        sum_ = 0\n",
    "        for i,val in enumerate(count):\n",
    "            sum_ += val * i\n",
    "            if val > max_freq:\n",
    "                max_freq = val\n",
    "                mode = i\n",
    "            if val > 0:\n",
    "                if min_num == 256:\n",
    "                    min_num = i\n",
    "                max_num = i\n",
    "            if cnt < right and cnt + val >= right:\n",
    "                median += i\n",
    "            if cnt < left and cnt + val >= left:\n",
    "                median += i\n",
    "            cnt += val\n",
    "        mean = sum_ / total\n",
    "        median = median / 2.0\n",
    "        return [min_num, max_num, mean, median, mode]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "\n",
    "    def sampleStats(self, count: List[int]) -> List[float]:\n",
    "\n",
    "        def find(i: int) -> int:\n",
    "\n",
    "            t = 0\n",
    "\n",
    "            for k, x in enumerate(count):\n",
    "\n",
    "                t += x\n",
    "\n",
    "                if t >= i:\n",
    "\n",
    "                    return k\n",
    "\n",
    "\n",
    "\n",
    "        mi, mx = inf, -1\n",
    "\n",
    "        s = cnt = 0\n",
    "\n",
    "        mode = 0\n",
    "\n",
    "        for k, x in enumerate(count):\n",
    "\n",
    "            if x:\n",
    "\n",
    "                mi = min(mi, k)\n",
    "\n",
    "                mx = max(mx, k)\n",
    "\n",
    "                s += k * x\n",
    "\n",
    "                cnt += x\n",
    "\n",
    "                if x > count[mode]:\n",
    "\n",
    "                    mode = k\n",
    "\n",
    "\n",
    "\n",
    "        median = find(cnt // 2 + 1) if cnt & 1 else (find(cnt // 2) + find(cnt // 2 + 1)) / 2\n",
    "\n",
    "        return [mi, mx, s / cnt, median, mode]\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sampleStats(self, count: List[int]) -> List[float]:\n",
    "        minimum = 0.0\n",
    "        for i in count:\n",
    "            if i != 0:\n",
    "                break\n",
    "            minimum += 1.0\n",
    "\n",
    "        maximum = 255.0\n",
    "        for i in count[-1::-1]:\n",
    "            if i != 0:\n",
    "                break\n",
    "            maximum -= 1.0\n",
    "\n",
    "        mean = 0\n",
    "        mean_numerator = 0\n",
    "        mean_denominator = 0\n",
    "        for i in range(256):\n",
    "            if count[i] != 0:\n",
    "                mean_numerator += i * count[i]\n",
    "                mean_denominator += count[i]\n",
    "        mean = mean_numerator/mean_denominator\n",
    "\n",
    "        median = 0.0\n",
    "        if mean_denominator%2 == 0:\n",
    "            rest = int(mean_denominator/2)\n",
    "            for i in range(256):\n",
    "                if rest - count[i] > 0:\n",
    "                    rest = rest - count[i]\n",
    "                    continue\n",
    "                elif rest - count[i] < 0:\n",
    "                    median = float(i)\n",
    "                    break\n",
    "                else:\n",
    "                    for j in range(i+1, 256):\n",
    "                        if count[j] != 0:\n",
    "                            median = float((i + j)/2)\n",
    "                            break\n",
    "                    break\n",
    "        elif mean_denominator%2 == 1:\n",
    "            rest = int((mean_denominator-1)/2)\n",
    "            for i in range(256):\n",
    "                if rest - count[i] < 0:\n",
    "                    median = float(i)\n",
    "                    break\n",
    "                rest = rest - count[i]\n",
    "\n",
    "        mode = 0.0\n",
    "        mode = float(count.index(max(count)))\n",
    "\n",
    "        return[minimum, maximum, mean, median, mode]\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sampleStats(self, count: List[int]) -> List[float]:\n",
    "        def find(i: int)->int:\n",
    "            t=0\n",
    "            for k,x in enumerate(count):\n",
    "                t+=x\n",
    "                if t>=i:\n",
    "                    return k\n",
    "        \n",
    "        mi,mx =inf,-1\n",
    "        s=cnt=0\n",
    "        mode=0\n",
    "        for k,x in enumerate(count):\n",
    "            if x:\n",
    "                mi=min(mi,k)\n",
    "                mx=max(mx,k)\n",
    "                s+=k*x\n",
    "                cnt+=x\n",
    "                if x>count[mode]:\n",
    "                    mode=k\n",
    "        \n",
    "        median=find(cnt//2+1) if cnt&1 else (find(cnt//2)+find(cnt//2+1))/2\n",
    "        return [mi,mx,s/cnt,median,mode]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sampleStats(self, count: List[int]) -> List[float]:\n",
    "        n=sum(count)\n",
    "        s=0\n",
    "        mode=-1\n",
    "        cnt=0\n",
    "        pre=0\n",
    "        med=-1\n",
    "        last=-1\n",
    "        minimum,maximum=-1,-1\n",
    "        \n",
    "        for i in range(256):\n",
    "            s+=i*count[i]\n",
    "            pre+=count[i]\n",
    "            if pre>n//2 and med==-1:\n",
    "                if n%2: med=i \n",
    "                else: \n",
    "                    if last>-1 and pre-count[i]==n//2:\n",
    "                        med=(i+last)/2\n",
    "                    else:\n",
    "                        med=i \n",
    "            if count[i]>cnt: \n",
    "                mode=i \n",
    "                cnt=count[i]\n",
    "            if count[i]: \n",
    "                if minimum==-1: minimum=i \n",
    "                maximum=i \n",
    "                last=i \n",
    "        mean=s/n\n",
    "        return [minimum, maximum, mean, med, mode]\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sampleStats(self, count: List[int]) -> List[float]:\n",
    "        n = len(count)\n",
    "        total = sum(count)\n",
    "        mean = 0.0\n",
    "        median = 0.0\n",
    "        min_num = 256\n",
    "        max_num = 0\n",
    "        mode = 0\n",
    "\n",
    "        left = (total + 1) // 2\n",
    "        right = (total + 2) // 2\n",
    "        cnt = 0\n",
    "        max_freq = 0\n",
    "        sum_ = 0\n",
    "        for i in range(n):\n",
    "            sum_ += count[i] * i\n",
    "            if count[i] > max_freq:\n",
    "                max_freq = count[i]\n",
    "                mode = i\n",
    "            if count[i] > 0:\n",
    "                if min_num == 256:\n",
    "                    min_num = i\n",
    "                max_num = i\n",
    "            if cnt < right and cnt + count[i] >= right:\n",
    "                median += i\n",
    "            if cnt < left and cnt + count[i] >= left:\n",
    "                median += i\n",
    "            cnt += count[i]\n",
    "        mean = sum_ / total\n",
    "        median = median / 2.0\n",
    "        return [min_num, max_num, mean, median, mode]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sampleStats(self, count: List[int]) -> List[float]:\n",
    "        minimum = -1\n",
    "        for i in range(256):\n",
    "            if count[i] > 0:\n",
    "                minimum = i\n",
    "                break\n",
    "        maximum = -1\n",
    "        for i in range(255, -1, -1):\n",
    "            if count[i] > 0:\n",
    "                maximum = i\n",
    "                break\n",
    "        summ = sum([i * count[i] for i in range(256)])\n",
    "        sum_num = sum(count)\n",
    "        mean = summ/sum_num\n",
    "        \n",
    "\n",
    "        median = -1\n",
    "        if sum_num % 2:\n",
    "            p = sum_num // 2 + 1 # 取较多的一半（多1）\n",
    "            for i in range(256):\n",
    "                p -= count[i]\n",
    "                if p <= 0:\n",
    "                    median = i\n",
    "                    break\n",
    "        else:\n",
    "            p = sum_num // 2\n",
    "            flag = 0\n",
    "            for i in range(256):\n",
    "                p -= count[i]\n",
    "                if p < 0:\n",
    "                    if flag == 1:\n",
    "                        median += i\n",
    "                        median /= 2\n",
    "                    else:\n",
    "                        median = i\n",
    "                    break\n",
    "                elif p == 0 and flag == 0:\n",
    "                    flag = 1\n",
    "                    median = i\n",
    "\n",
    "        mode = count.index(max(count))\n",
    "        return minimum, maximum, mean, median, mode\n",
    "        \n",
    "                \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sampleStats(self, count: List[int]) -> List[float]:\n",
    "        cnt = []\n",
    "        n = s = 0\n",
    "        for i, c in enumerate(count):\n",
    "            if c != 0:\n",
    "                s += i * c\n",
    "                n += c\n",
    "                cnt.append((c, i))\n",
    "        midL = midR = -1\n",
    "        midCnt = 0\n",
    "        mid = (n + 1) // 2\n",
    "        even = (n % 2) == 0\n",
    "        for c, num in cnt:\n",
    "            midCnt += c\n",
    "            if midL == -1:\n",
    "                if midCnt >= mid:\n",
    "                    midL = num\n",
    "            if even and midR == -1:\n",
    "                if midCnt >= (mid + 1):\n",
    "                    midR = num\n",
    "            if (even and midL != -1 and midR != -1) or (not even and midL != -1):\n",
    "                break\n",
    "        return [float(cnt[0][1]), float(cnt[-1][1]), s / n, (midL + midR) / 2 if even else midL, sorted(cnt)[-1][1]]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sampleStats(self, count: List[int]) -> List[float]:\n",
    "        minimum = None\n",
    "        maximum = None\n",
    "        current_sum = 0\n",
    "        current_count = 0\n",
    "        median1 = None\n",
    "        median2 = None\n",
    "        total_count = sum(count)\n",
    "        max_freq = 0\n",
    "        for k, nk in enumerate(count):\n",
    "            if current_count == total_count:\n",
    "                break\n",
    "            \n",
    "            # 计算最大值\n",
    "            if nk != 0:\n",
    "                if minimum is None:\n",
    "                    minimum = k\n",
    "                \n",
    "                maximum = k\n",
    "\n",
    "                current_sum += k * nk\n",
    " \n",
    "                current_count += nk\n",
    "                if median1 is None:\n",
    "                    if current_count >= (total_count // 2 + 1):\n",
    "                        median1 = k\n",
    "                \n",
    "                if median2 is None: \n",
    "                    if current_count >= (total_count + 1) // 2:\n",
    "                        median2 = k\n",
    "\n",
    "                if nk > max_freq:\n",
    "                    mode = k\n",
    "                    max_freq = nk\n",
    "\n",
    "        results = [\n",
    "            float(minimum), \n",
    "            float(maximum), \n",
    "            float(current_sum / total_count), \n",
    "            float(median1 + median2) / 2, \n",
    "            float(mode)\n",
    "        ]\n",
    "\n",
    "        return results                \n",
    "            "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sampleStats(self, count: List[int]) -> List[float]:\n",
    "        def find(i: int) -> int:\n",
    "            t = 0\n",
    "            for k, x in enumerate(count):\n",
    "                t += x\n",
    "                if t >= i:\n",
    "                    return k\n",
    "\n",
    "        mi, mx = inf, -1\n",
    "        s = cnt = 0\n",
    "        mode = 0\n",
    "        for k, x in enumerate(count):\n",
    "            if x:\n",
    "                mi = min(mi, k)\n",
    "                mx = max(mx, k)\n",
    "                s += k * x\n",
    "                cnt += x\n",
    "                if x > count[mode]:\n",
    "                    mode = k\n",
    "\n",
    "        median = find(cnt // 2 + 1) if cnt & 1 else (find(cnt // 2) + find(cnt // 2 + 1)) / 2\n",
    "        return [mi, mx, s / cnt, median, mode]\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sampleStats(self, count: List[int]) -> List[float]:\n",
    "        res = [0.0 for i in range(5)]\n",
    "        minimum_flag = True\n",
    "        sum_ = 0\n",
    "        cnt = 0\n",
    "        mode = 0\n",
    "        for i in range(256):\n",
    "            if count[i] != 0:\n",
    "                if minimum_flag:\n",
    "                    res[0] = i\n",
    "                    res[1] = i\n",
    "                    minimum_flag = False\n",
    "                else:\n",
    "                    res[1] = i\n",
    "                if count[i] > mode:\n",
    "                    mode = count[i]\n",
    "                    res[4] = i\n",
    "                sum_ += count[i]*i\n",
    "                cnt += count[i]\n",
    "        res[0] = float(res[0])\n",
    "        res[1] = float(res[1])\n",
    "        res[4] = float(res[4])\n",
    "        res[2] = sum_/cnt\n",
    "        # if cnt == 0:\n",
    "        #     return res\n",
    "        if cnt%2 == 0:\n",
    "            cnt >>= 1\n",
    "            tmp = 0\n",
    "            flag_1 = False\n",
    "            for i in range(256):\n",
    "                if count[i] != 0:\n",
    "                    tmp += count[i]\n",
    "                    if tmp >= cnt:\n",
    "                        if flag_1:\n",
    "                            res[3] = (res[3]+i)/2\n",
    "                            return res\n",
    "                        else:\n",
    "                            if tmp >= cnt+1:\n",
    "                                res[3] = float(i)\n",
    "                                return res\n",
    "                            else:\n",
    "                                flag_1 = True\n",
    "                                res[3] = float(i)\n",
    "\n",
    "        else:\n",
    "            cnt = (cnt+1)/2\n",
    "            tmp = 0\n",
    "            for i in range(256):\n",
    "                if count[i] != 0:\n",
    "                    tmp += count[i]\n",
    "                    if tmp >= cnt:\n",
    "                        res[3] += i\n",
    "                        return res\n",
    "\n",
    "        \n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sampleStats(self, count: List[int]) -> List[float]:\n",
    "        def find(i: int) -> int:\n",
    "            temp = 0\n",
    "            for index, x in enumerate(count):\n",
    "                temp += x\n",
    "                if temp >= i:\n",
    "                    return index\n",
    "\n",
    "        mininum, maxinum = inf, -1\n",
    "        s = cnt = 0\n",
    "        mode = 0\n",
    "        for index, x in enumerate(count):\n",
    "            if x != 0:\n",
    "                cnt += x\n",
    "                s += (index * x)\n",
    "                mininum = min(mininum, index)\n",
    "                maxinum = max(maxinum, index)\n",
    "                if x > count[mode]:\n",
    "                    mode = index\n",
    "        median = find(cnt // 2 + 1) if cnt % 2 == 1 else (find(cnt // 2) + find(cnt // 2 + 1)) / 2\n",
    "        return [mininum, maxinum, s / cnt, median, mode]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sampleStats(self, count: List[int]) -> List[float]:\n",
    "        minimum = -1\n",
    "        for i in range(256):\n",
    "            if count[i] > 0:\n",
    "                minimum = i\n",
    "                break\n",
    "        maximum = -1\n",
    "        for i in range(255, -1, -1):\n",
    "            if count[i] > 0:\n",
    "                maximum = i\n",
    "                break\n",
    "        summ = sum([i * count[i] for i in range(256)])\n",
    "        sum_num = sum(count)\n",
    "        mean = summ/sum_num\n",
    "        \n",
    "\n",
    "        median = -1\n",
    "        if sum_num % 2:\n",
    "            p = sum_num // 2 + 1 # 取较多的一半（多1）\n",
    "            for i in range(256):\n",
    "                p -= count[i]\n",
    "                if p <= 0:\n",
    "                    median = i\n",
    "                    break\n",
    "        else:\n",
    "            p = sum_num // 2\n",
    "            flag = 0\n",
    "            for i in range(256):\n",
    "                p -= count[i]\n",
    "                if p < 0:\n",
    "                    if flag == 1:\n",
    "                        median += i\n",
    "                        median /= 2\n",
    "                    else:\n",
    "                        median = i\n",
    "                    break\n",
    "                elif p == 0 and flag == 0:\n",
    "                    flag = 1\n",
    "                    median = i\n",
    "\n",
    "        mode = count.index(max(count))\n",
    "        return minimum, maximum, mean, median, mode\n",
    "        \n",
    "                \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "\n",
    "    def sampleStats(self, count: List[int]) -> List[float]:\n",
    "\n",
    "        def find(i: int) -> int:\n",
    "\n",
    "            t = 0\n",
    "\n",
    "            for k, x in enumerate(count):\n",
    "\n",
    "                t += x\n",
    "\n",
    "                if t >= i:\n",
    "\n",
    "                    return k\n",
    "\n",
    "\n",
    "\n",
    "        mi, mx = inf, -1\n",
    "\n",
    "        s = cnt = 0\n",
    "\n",
    "        mode = 0\n",
    "\n",
    "        for k, x in enumerate(count):\n",
    "\n",
    "            if x:\n",
    "\n",
    "                mi = min(mi, k)\n",
    "\n",
    "                mx = max(mx, k)\n",
    "\n",
    "                s += k * x\n",
    "\n",
    "                cnt += x\n",
    "\n",
    "                if x > count[mode]:\n",
    "\n",
    "                    mode = k\n",
    "\n",
    "\n",
    "\n",
    "        median = find(cnt // 2 + 1) if cnt & 1 else (find(cnt // 2) + find(cnt // 2 + 1)) / 2\n",
    "\n",
    "        return [mi, mx, s / cnt, median, mode]\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sampleStats(self, count: List[int]) -> List[float]:\n",
    "        ans = []\n",
    "        start = 0\n",
    "        for i, j in enumerate(count):\n",
    "            if j!=0:\n",
    "                ans.append(i)\n",
    "                start = i\n",
    "                break\n",
    "        end = 0\n",
    "        for i, j in enumerate(count[::-1]):\n",
    "            if j!=0:\n",
    "                ans.append(255-i)\n",
    "                end = 256-i\n",
    "                break\n",
    "        s = sum(count)\n",
    "        x = 0\n",
    "        t = 0\n",
    "        for i in range(start, end):\n",
    "            if count[i]>t:\n",
    "                mode = i \n",
    "                t = count[i]\n",
    "            x += i*count[i]\n",
    "        ans.append(x/s)\n",
    "        n = s//2\n",
    "\n",
    "        if s%2==0:\n",
    "            median = 0\n",
    "            for i in range(start, end):\n",
    "                if count[i]>n:\n",
    "                    if median==0:\n",
    "                        median = i\n",
    "                    else:\n",
    "                        median+=i\n",
    "                        median/=2\n",
    "                    break\n",
    "                if count[i]==n and count[i]!=0:\n",
    "                    median = i      \n",
    "                n -= count[i]\n",
    "        else:\n",
    "            for i in range(start, end):\n",
    "                if count[i]>n:\n",
    "                    median = i\n",
    "                    break  \n",
    "                n -= count[i]\n",
    "        ans.append(median)\n",
    "        ans.append(mode)\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sampleStats(self, count: List[int]) -> List[float]:\n",
    "        mininum = 255\n",
    "        maximun = 0\n",
    "        sum = 0\n",
    "        total = 0\n",
    "        mode = 0\n",
    "        time = 0\n",
    "        for i in range(256):\n",
    "            if mininum == 255 and count[i] != 0:\n",
    "                mininum = i\n",
    "            if count[i] != 0:\n",
    "                maximun = i\n",
    "            sum += i * count[i]\n",
    "            total += count[i]\n",
    "            if count[i] > time:\n",
    "                mode = i\n",
    "                time = count[i]\n",
    "        mean = sum / total\n",
    "        median = 0\n",
    "        if total % 2 == 0:\n",
    "            half = total // 2\n",
    "            for i in range(256):\n",
    "                if count[i]==0:\n",
    "                    continue\n",
    "                half -= count[i]\n",
    "                if half == 0:\n",
    "                    median += i\n",
    "                elif half < 0:\n",
    "                    if median ==0:\n",
    "                        median = i\n",
    "                    else:\n",
    "                        median=(median+i)/2\n",
    "                    break\n",
    "        else:\n",
    "            half = total // 2\n",
    "            for i in range(256):\n",
    "                half -= count[i]\n",
    "                if half < 0:\n",
    "                    median = i\n",
    "                    break\n",
    "        return [mininum, maximun, mean, median, mode]\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sampleStats(self, count: List[int]) -> List[float]:\n",
    "        n = len(count)\n",
    "        total = sum(count)\n",
    "        mean = 0.0\n",
    "        median = 0.0\n",
    "        min_num = 256\n",
    "        max_num = 0\n",
    "        mode = 0\n",
    "\n",
    "        left = (total + 1) // 2\n",
    "        right = (total + 2) // 2\n",
    "        cnt = 0\n",
    "        max_freq = 0\n",
    "        sum_ = 0\n",
    "        for i in range(n):\n",
    "            sum_ += count[i] * i\n",
    "            if count[i] > max_freq:\n",
    "                max_freq = count[i]\n",
    "                mode = i\n",
    "            if count[i] > 0:\n",
    "                if min_num == 256:\n",
    "                    min_num = i\n",
    "                max_num = i\n",
    "            if cnt < right and cnt + count[i] >= right:\n",
    "                median += i\n",
    "            if cnt < left and cnt + count[i] >= left:\n",
    "                median += i\n",
    "            cnt += count[i]\n",
    "        mean = sum_ / total\n",
    "        median = median / 2.0\n",
    "        return [min_num, max_num, mean, median, mode]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sampleStats(self, count: List[int]) -> List[float]:\n",
    "        def find(i: int) -> int:\n",
    "            t = 0\n",
    "            for k, x in enumerate(count):\n",
    "                t += x\n",
    "                if t >= i:\n",
    "                    return k\n",
    "\n",
    "        mi, mx = inf, -1\n",
    "        s = cnt = 0\n",
    "        mode = 0\n",
    "        for k, x in enumerate(count):\n",
    "            if x:\n",
    "                mi = min(mi, k)\n",
    "                mx = max(mx, k)\n",
    "                s += k * x\n",
    "                cnt += x\n",
    "                if x > count[mode]:\n",
    "                    mode = k\n",
    "\n",
    "        median = find(cnt // 2 + 1) if cnt & 1 else (find(cnt // 2) + find(cnt // 2 + 1)) / 2\n",
    "        return [mi, mx, s / cnt, median, mode]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sampleStats(self, count: List[int]) -> List[float]:\n",
    "        res = [0.0 for i in range(5)]\n",
    "        minimum_flag = True\n",
    "        sum_ = 0\n",
    "        cnt = 0\n",
    "        mode = 0\n",
    "        for i in range(256):\n",
    "            if count[i] != 0:\n",
    "                if minimum_flag:\n",
    "                    res[0] = i\n",
    "                    res[1] = i\n",
    "                    minimum_flag = False\n",
    "                else:\n",
    "                    res[1] = i\n",
    "                if count[i] > mode:\n",
    "                    mode = count[i]\n",
    "                    res[4] = i\n",
    "                sum_ += count[i]*i\n",
    "                cnt += count[i]\n",
    "        res[0] = float(res[0])\n",
    "        res[1] = float(res[1])\n",
    "        res[4] = float(res[4])\n",
    "        res[2] = sum_/cnt\n",
    "        # if cnt == 0:\n",
    "        #     return res\n",
    "        if cnt%2 == 0:\n",
    "            cnt >>= 1\n",
    "            tmp = 0\n",
    "            flag_1 = False\n",
    "            for i in range(256):\n",
    "                if count[i] != 0:\n",
    "                    tmp += count[i]\n",
    "                    if tmp >= cnt:\n",
    "                        if flag_1:\n",
    "                            res[3] = (res[3]+i)/2\n",
    "                            return res\n",
    "                        else:\n",
    "                            if tmp >= cnt+1:\n",
    "                                res[3] = float(i)\n",
    "                                return res\n",
    "                            else:\n",
    "                                flag_1 = True\n",
    "                                res[3] = float(i)\n",
    "\n",
    "        else:\n",
    "            cnt = (cnt+1)/2\n",
    "            tmp = 0\n",
    "            for i in range(256):\n",
    "                if count[i] != 0:\n",
    "                    tmp += count[i]\n",
    "                    if tmp >= cnt:\n",
    "                        res[3] += i\n",
    "                        return res\n",
    "\n",
    "        \n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sampleStats(self, count: List[int]) -> List[float]:\n",
    "        # 初始化变量\n",
    "        n, lst = sum(count), list(accumulate(count))\n",
    "        # 一次遍历count，找到第一个非0的index，就是minimum\n",
    "        for minimum in range(256):\n",
    "            if count[minimum] != 0: break\n",
    "        # 倒序一次遍历count，找到第一个非0的index，就是maximum\n",
    "        for maximum in range(255, -1, -1):\n",
    "            if count[maximum] != 0: break    \n",
    "        # mean ：样本的平均值，计算为所有元素的总和除以元素总数。\n",
    "        mean = sum(i * c for i, c in enumerate(count)) / n    \n",
    "        median = bisect.bisect_left(lst, (n >> 1) + 1) if n & 1 else (bisect.bisect_left(lst, n >> 1) + bisect.bisect_left(lst, (n >> 1) + 1)) / 2.0\n",
    "        mode = count.index(max(count))\n",
    "        return minimum, maximum, mean, median, mode\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sampleStats(self, count: List[int]) -> List[float]:\n",
    "        res = [0.0 for i in range(5)]\n",
    "        minimum_flag = True\n",
    "        sum_ = 0\n",
    "        cnt = 0\n",
    "        mode = 0\n",
    "        for i in range(256):\n",
    "            if count[i] != 0:\n",
    "                if minimum_flag:\n",
    "                    res[0] = i\n",
    "                    res[1] = i\n",
    "                    minimum_flag = False\n",
    "                else:\n",
    "                    res[1] = i\n",
    "                if count[i] > mode:\n",
    "                    mode = count[i]\n",
    "                    res[4] = i\n",
    "                sum_ += count[i]*i\n",
    "                cnt += count[i]\n",
    "        # res[0] = float(res[0])\n",
    "        # res[1] = float(res[1])\n",
    "        # res[4] = float(res[4])\n",
    "        res[2] = sum_/cnt\n",
    "        # if cnt == 0:\n",
    "        #     return res\n",
    "        if cnt%2 == 0:\n",
    "            cnt >>= 1\n",
    "            tmp = 0\n",
    "            flag_1 = False\n",
    "            for i in range(256):\n",
    "                if count[i] != 0:\n",
    "                    tmp += count[i]\n",
    "                    if tmp >= cnt:\n",
    "                        if flag_1:\n",
    "                            res[3] = (res[3]+i)/2\n",
    "                            return res\n",
    "                        else:\n",
    "                            if tmp >= cnt+1:\n",
    "                                res[3] = i\n",
    "                                return res\n",
    "                            else:\n",
    "                                flag_1 = True\n",
    "                                res[3] = i\n",
    "\n",
    "        else:\n",
    "            cnt = (cnt+1)/2\n",
    "            tmp = 0\n",
    "            for i in range(256):\n",
    "                if count[i] != 0:\n",
    "                    tmp += count[i]\n",
    "                    if tmp >= cnt:\n",
    "                        res[3] += i\n",
    "                        return res\n",
    "\n",
    "        \n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sampleStats(self, count: List[int]) -> List[float]:\n",
    "        def find(i: int) -> int:\n",
    "            temp = 0\n",
    "            for index, x in enumerate(count):\n",
    "                temp += x\n",
    "                if temp >= i:\n",
    "                    return index\n",
    "\n",
    "        mininum, maxinum = inf, -1\n",
    "        s = cnt = 0\n",
    "        mode = 0\n",
    "        for index, x in enumerate(count):\n",
    "            if x != 0:\n",
    "                cnt += x\n",
    "                s += (index * x)\n",
    "                mininum = min(mininum, index)\n",
    "                maxinum = max(maxinum, index)\n",
    "                if x > count[mode]:\n",
    "                    mode = index\n",
    "        median = find(cnt // 2 + 1) if cnt % 2 == 1 else (find(cnt // 2) + find(cnt // 2 + 1)) / 2\n",
    "        return [mininum, maxinum, s / cnt, median, mode]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sampleStats(self, count: List[int]) -> List[float]:\n",
    "        n,cnt,pre,last=sum(count),0,0,-1\n",
    "        s,med,mode,minimum,maximum=0,-1,-1,-1,-1\n",
    "        for i in range(256):\n",
    "            s+=i*count[i]\n",
    "            pre+=count[i]\n",
    "            if pre>n//2 and med==-1:\n",
    "                if n%2==0 and last>-1 and pre-count[i]==n//2: med=(i+last)/2 \n",
    "                else: med=i \n",
    "            if count[i]>cnt: \n",
    "                mode=i \n",
    "                cnt=count[i]\n",
    "            if count[i]: \n",
    "                if minimum==-1: minimum=i \n",
    "                maximum=i \n",
    "                last=i \n",
    "        mean=s/n\n",
    "        return [minimum, maximum, mean, med, mode]\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sampleStats(self, count: List[int]) -> List[float]:\n",
    "        # 初始化变量\n",
    "        n, lst = sum(count), list(accumulate(count))\n",
    "        # 一次遍历count，找到第一个非0的index，就是minimum\n",
    "        for minimum in range(256):\n",
    "            if count[minimum] != 0: break\n",
    "        # 倒序一次遍历count，找到第一个非0的index，就是maximum\n",
    "        for maximum in range(255, -1, -1):\n",
    "            if count[maximum] != 0: break    \n",
    "        # mean ：样本的平均值，计算为所有元素的总和除以元素总数。\n",
    "        mean = sum(i * c for i, c in enumerate(count)) / n    \n",
    "        median = bisect.bisect_left(lst, (n >> 1) + 1) if n & 1 else (bisect.bisect_left(lst, n >> 1) + bisect.bisect_left(lst, (n >> 1) + 1)) / 2.0\n",
    "        mode = count.index(max(count))\n",
    "        return minimum, maximum, mean, median, mode\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sampleStats(self, count: List[int]) -> List[float]:\n",
    "        n = sum(count)\n",
    "        s = 0\n",
    "        maximum = -inf\n",
    "        minimum = inf\n",
    "        if n%2 == 0:\n",
    "            l = n//2\n",
    "            r = l+1\n",
    "        else:\n",
    "            l = n//2+1\n",
    "            r = l\n",
    "        l1 = r1 = 0\n",
    "        # print(l,r)\n",
    "        maxcnt = count[0]\n",
    "        mode = 0\n",
    "        cnt = 0\n",
    "        for i,c in enumerate(count):\n",
    "            if c != 0:\n",
    "                s += i*c\n",
    "                maximum = max(maximum,i)\n",
    "                minimum = min(minimum,i)\n",
    "                if c > maxcnt:\n",
    "                    maxcnt = c\n",
    "                    mode = i\n",
    "                # print(cnt,cnt+c,l,r)\n",
    "                if cnt<l<=cnt+c:\n",
    "                    print(cnt,cnt+c,l)\n",
    "                    l1 = i\n",
    "                if cnt<r<=cnt+c:\n",
    "                    r1 = i\n",
    "                cnt += c\n",
    "        return [minimum,maximum,s/n,(l1+r1)/2,mode]\n",
    "                \n",
    "                    \n",
    "            \n",
    "        \n",
    "                "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sampleStats(self, count: List[int]) -> List[float]:\n",
    "        def find(i: int) -> int:\n",
    "            t = 0\n",
    "            for k, x in enumerate(count):\n",
    "                t += x\n",
    "                if t >= i:\n",
    "                    return k\n",
    "\n",
    "        mi, mx = inf, -1\n",
    "        s = cnt = 0\n",
    "        mode = 0\n",
    "        for k, x in enumerate(count):\n",
    "            if x:\n",
    "                mi = min(mi, k)\n",
    "                mx = max(mx, k)\n",
    "                s += k * x\n",
    "                cnt += x\n",
    "                if x > count[mode]:\n",
    "                    mode = k\n",
    "\n",
    "        median = find(cnt // 2 + 1) if cnt & 1 else (find(cnt // 2) + find(cnt // 2 + 1)) / 2\n",
    "        return [mi, mx, s / cnt, median, mode]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sampleStats(self, count: List[int]) -> List[float]:\n",
    "        tot = sum(count)\n",
    "        s = 0\n",
    "        n = len(count)\n",
    "        t = tot // 2 + 1\n",
    "        left, right = 0, 0\n",
    "        mn = mx = -1\n",
    "        mode = mxv = 0\n",
    "        m1 = m2 = 0\n",
    "        med = -1\n",
    "        for i, x in enumerate(count):\n",
    "            if x == 0 :continue\n",
    "            if mn == -1:\n",
    "                mn = i\n",
    "            mx = i\n",
    "            if x > mxv:\n",
    "                mxv = x\n",
    "                mode = i\n",
    "            s += x * i\n",
    "            left += x\n",
    "            if left >= t and med == -1:\n",
    "                # print(i, x, left, t)\n",
    "                med = i\n",
    "        if tot % 2 == 0:\n",
    "            for i in range(n):  \n",
    "                if count[i]:\n",
    "                    right += count[i]\n",
    "                    if right >= t - 1:\n",
    "                        med = (med + i) /2\n",
    "                        break\n",
    "        # print(tot, left, right, med)\n",
    "        return [mn, mx, s/tot, med, mode]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sampleStats(self, count: List[int]) -> List[float]:\n",
    "        n = len(count)\n",
    "        total = sum(count)\n",
    "        mean = 0.0\n",
    "        median = 0.0\n",
    "        min_num = 256\n",
    "        max_num = 0\n",
    "        mode = 0\n",
    "\n",
    "        left = (total + 1) // 2\n",
    "        right = (total + 2) // 2\n",
    "        cnt = 0\n",
    "        max_freq = 0\n",
    "        sum_ = 0\n",
    "        for i in range(n):\n",
    "            sum_ += count[i] * i\n",
    "            if count[i] > max_freq:\n",
    "                max_freq = count[i]\n",
    "                mode = i\n",
    "            if count[i] > 0:\n",
    "                if min_num == 256:\n",
    "                    min_num = i\n",
    "                max_num = i\n",
    "            if cnt < right and cnt + count[i] >= right:\n",
    "                median += i\n",
    "            if cnt < left and cnt + count[i] >= left:\n",
    "                median += i\n",
    "            cnt += count[i]\n",
    "        mean = sum_ / total\n",
    "        median = median / 2.0\n",
    "        return [min_num, max_num, mean, median, mode]\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sampleStats(self, count: List[int]) -> List[float]:\n",
    "        n = len(count)\n",
    "        total = sum(count)\n",
    "        mean = 0.0\n",
    "        median = 0.0\n",
    "        min_num = 256\n",
    "        max_num = 0\n",
    "        mode = 0\n",
    "\n",
    "        left = (total + 1) // 2\n",
    "        right = (total + 2) // 2\n",
    "        cnt = 0\n",
    "        max_freq = 0\n",
    "        sum_ = 0\n",
    "        for i,val in enumerate(count):\n",
    "            sum_ += val * i\n",
    "            if val > max_freq:\n",
    "                max_freq = val\n",
    "                mode = i\n",
    "            if val > 0:\n",
    "                if min_num == 256:\n",
    "                    min_num = i\n",
    "                max_num = i\n",
    "            if cnt < right and cnt + val >= right:\n",
    "                median += i\n",
    "            if cnt < left and cnt + val >= left:\n",
    "                median += i\n",
    "            cnt += val\n",
    "        mean = sum_ / total\n",
    "        median = median / 2.0\n",
    "        return [min_num, max_num, mean, median, mode]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sampleStats(self, count: List[int]) -> List[float]:\n",
    "        minimum = 0\n",
    "        while not count[minimum]: minimum+=1\n",
    "        minimum = float(minimum)\n",
    "        maximum  = 255\n",
    "        while not count[maximum]: maximum-=1\n",
    "        maximum = float(maximum)\n",
    "        mean = 0\n",
    "        mode = 0\n",
    "        for idx,num in enumerate(count):\n",
    "            mean+=num*idx\n",
    "            if num>count[mode]:\n",
    "                mode=idx\n",
    "        mean = mean/sum(count)\n",
    "        mode = float(mode)\n",
    "        sum_count = sum(count)\n",
    "        median = 0\n",
    "        if sum_count%2:\n",
    "            median_idx = sum_count//2\n",
    "            cur_idx = 0\n",
    "            for idx,num in enumerate(count):\n",
    "                if cur_idx<=median_idx and cur_idx+num-1>=median_idx:\n",
    "                    print(idx,num,median)\n",
    "                    median = idx\n",
    "                    break\n",
    "                cur_idx+=num\n",
    "            median = float(median)\n",
    "        else:\n",
    "            median_idx = sum_count//2\n",
    "            cur_idx = 0\n",
    "            median = 0\n",
    "            for idx,num in enumerate(count):\n",
    "                \n",
    "                if cur_idx<=median_idx-1 and cur_idx+num-1>=median_idx-1:\n",
    "                    median += idx\n",
    "                if  cur_idx<=median_idx and cur_idx+num-1>=median_idx:\n",
    "                    median += idx\n",
    "                    break\n",
    "                cur_idx+=num\n",
    "            median = float(median)/2\n",
    "        return [minimum, maximum, mean, median, mode]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sampleStats(self, count: List[int]) -> List[float]:\n",
    "        n=sum(count)\n",
    "        minnum=float('inf')\n",
    "        for i in range(len(count)):\n",
    "            if count[i]!=0:\n",
    "                minnum=i\n",
    "                break\n",
    "        maxnum=0\n",
    "        for i in range(len(count)):\n",
    "            if count[i]!=0:\n",
    "                if i>maxnum:\n",
    "                    maxnum=i\n",
    "        mode=0\n",
    "        mode_num=0\n",
    "        for i in range(len(count)):\n",
    "            if count[i]>mode_num:\n",
    "                mode_num=count[i]\n",
    "                mode=i\n",
    "        mean=0\n",
    "        for i in range((len(count))):\n",
    "            if count[i]>0:\n",
    "                mean=mean+count[i]*i\n",
    "        mean=mean/n\n",
    "        \n",
    "        median=0\n",
    "        if n%2==1:\n",
    "            median_index=n//2\n",
    "            pre=0\n",
    "            for i in range(len(count)):\n",
    "                pre+=count[i]\n",
    "                if pre>median_index:\n",
    "                    median=i\n",
    "                    break\n",
    "\n",
    "        else:\n",
    "            median1=0\n",
    "            median1_index=n//2\n",
    "            median2=0\n",
    "            median2_index=n//2+1\n",
    "            use_1=True\n",
    "            pre=0\n",
    "            for i in range(len(count)):\n",
    "                if count[i]!=0:\n",
    "                    pre+=count[i]\n",
    "                    if pre>=median1_index and pre>=median2_index:\n",
    "                        if use_1:\n",
    "                            median1=i\n",
    "                            median2=i\n",
    "                            break\n",
    "                        else:\n",
    "                            median2=i\n",
    "                            break\n",
    "                    elif pre>=median1_index and pre<median2_index:\n",
    "                        median1=i\n",
    "                        use_1=False\n",
    "            median=(median1+median2)/2\n",
    "\n",
    "        return [minnum, maxnum, mean, median, mode]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sampleStats(self, count: List[int]) -> List[float]:\n",
    "        n=sum(count)\n",
    "        print(n) \n",
    "        s=0\n",
    "        mode=-1\n",
    "        cnt=0\n",
    "        pre=0\n",
    "        med=-1\n",
    "        last,now=-1,-1\n",
    "        for i in range(256):\n",
    "            if count[i]:\n",
    "                minimum=i\n",
    "                break\n",
    "        for i in range(255,-1,-1):\n",
    "            if count[i]:\n",
    "                maximum=i\n",
    "                break\n",
    "        for i in range(256):\n",
    "            s+=i*count[i]\n",
    "            pre+=count[i]\n",
    "            if pre>n//2 and med==-1:\n",
    "                if n%2: med=i \n",
    "                else: \n",
    "                    if last>-1 and pre-count[i]==n//2:\n",
    "                        med=(i+last)/2\n",
    "                    else:\n",
    "                        med=i \n",
    "            if count[i]>cnt: \n",
    "                mode=i \n",
    "                cnt=count[i]\n",
    "            if count[i]: last=i \n",
    "        mean=s/n\n",
    "        return [minimum, maximum, mean, med, mode]\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sampleStats(self, count: List[int]) -> List[float]:\n",
    "        minimum = None\n",
    "        maximum = None\n",
    "        mode = 0\n",
    "        total = 0\n",
    "        n = 0\n",
    "        \n",
    "        for i in range(len(count)):\n",
    "            if count[i] > 0:\n",
    "                if not minimum and minimum != 0:\n",
    "                    minimum=i\n",
    "                maximum = i\n",
    "\n",
    "                n += count[i]\n",
    "                total += i * count[i]\n",
    "\n",
    "            if count[i] > count[mode]:\n",
    "                mode = i\n",
    "\n",
    "        n_median = 0\n",
    "        for i in range(len(count)):\n",
    "            if count[i] > 0:\n",
    "                n_median += count[i]\n",
    "\n",
    "                if n_median > (n-1) // 2:\n",
    "                    if n % 2 == 1:\n",
    "                        median = i\n",
    "                        break\n",
    "                    else:\n",
    "                        median = i\n",
    "                        if n_median > (n-1) // 2 + 1:\n",
    "                            break\n",
    "                        else:\n",
    "                            for j in range(i+1, len(count)):\n",
    "                                if count[j] > 0:\n",
    "                                    median = (i + j) / 2\n",
    "                                    break\n",
    "                            break                            \n",
    "\n",
    "        \n",
    "        return [minimum, maximum, total/n, median, mode]\n",
    "\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sampleStats(self, count: List[int]) -> List[float]:\n",
    "        ans = [0] * 5\n",
    "        lst = [*accumulate(count)]\n",
    "        ans[0] = next(i for i, n in enumerate(count) if n)  # 最小值\n",
    "        ans[1] = next(255 - i for i, n in enumerate(count[::-1]) if n)  # 最大值\n",
    "        ans[2] = sum(i * n for i, n in enumerate(count)) / lst[-1]   # 平均数\n",
    "        left = lst[-1] + 1 >> 1\n",
    "        right = lst[-1] + 2 >> 1\n",
    "        ans[3] = (bisect_left(lst, left) + bisect_left(lst, right)) / 2# 中位数\n",
    "        ans[4] = count.index(max(count))    # 众数\n",
    "        return ans\n",
    "        \n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sampleStats(self, count: list[int]) -> list[float]:\n",
    "        mean = median = mode = 0\n",
    "        text = True\n",
    "        number = quan = times = 0\n",
    "        for i in count:\n",
    "            if i:\n",
    "                if text:\n",
    "                    text = False\n",
    "                    minimum = number\n",
    "                maximum = number\n",
    "                quan += i\n",
    "                mean += number * i\n",
    "                if i > times:\n",
    "                    times = i\n",
    "                    mode = number\n",
    "            number += 1\n",
    "\n",
    "        mean = mean / quan\n",
    "        quan_second = number = 0\n",
    "        last = -1\n",
    "        print(quan, quan / 2)\n",
    "        for i in count:\n",
    "            if i:\n",
    "                quan_second += i\n",
    "                print(number, quan_second, last)\n",
    "                if quan_second == int(quan / 2) and quan % 2 - 1:\n",
    "                    last = number\n",
    "                elif last != -1:\n",
    "                    median = (last + number) / 2\n",
    "                    break\n",
    "                elif quan_second > quan / 2:\n",
    "                    median = number\n",
    "                    break\n",
    "            number += 1\n",
    "        return [minimum, maximum, mean, median, mode]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sampleStats(self, count: List[int]) -> List[float]:\n",
    "        length = sum(count)\n",
    "        target = length // 2\n",
    "        flag = length % 2 == 0\n",
    "        f = True\n",
    "        length_ = len(count)\n",
    "        index = 0\n",
    "        total, c = 0, 0\n",
    "        most = 0\n",
    "        r = [0.0, 0.0, 0.0, 0.0, 0.0]\n",
    "        while index < length_:\n",
    "            if count[index] > 0:\n",
    "                if most == 0:\n",
    "                    r[0] = float(index)\n",
    "                if count[index] > most:\n",
    "                    most = count[index]\n",
    "                    r[-1] = float(index)\n",
    "                r[1] = float(index)\n",
    "                total += index * count[index]\n",
    "                c += count[index]\n",
    "                if c == target:\n",
    "                    if flag:\n",
    "                        r[-2] = index\n",
    "                elif c > target:\n",
    "                    if f:\n",
    "                        if r[-2] != 0:\n",
    "                            r[-2] = (r[-2] + index) / 2\n",
    "                        else:\n",
    "                            r[-2] = float(index)\n",
    "                        f = False\n",
    "            index += 1\n",
    "        r[2] = total / length\n",
    "        return r\n",
    "                "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sampleStats(self, count: List[int]) -> List[float]:\n",
    "        total_num=sum(count)\n",
    "        num=0\n",
    "        mode=0\n",
    "        summ=0\n",
    "        minimum=-1\n",
    "        median=-1\n",
    "        tmp=0\n",
    "        max_c=0\n",
    "        for i,c in enumerate(count): \n",
    "            if c==0:\n",
    "                continue\n",
    "            num+=c\n",
    "            summ+=c*i\n",
    "            if max_c<c:\n",
    "                mode,max_c=i,c\n",
    "            if  minimum==-1:\n",
    "                minimum=i\n",
    "            maximum=i\n",
    "            if median==-1 :\n",
    "                #总个数是奇数\n",
    "                if (total_num)%2:\n",
    "                    if num>=total_num//2+1:\n",
    "                        median=i\n",
    "                #总个数是偶数\n",
    "                else:\n",
    "\n",
    "                    if num==(total_num//2):\n",
    "                        \n",
    "                        tmp+=i\n",
    "                    if num>(total_num//2):\n",
    "                        if tmp:\n",
    "                            median=(i+tmp)/2\n",
    "                        else:\n",
    "                            median=i\n",
    "        \n",
    "        mean=summ/num\n",
    "        return [minimum,maximum,mean,median,mode]\n",
    "\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sampleStats(self, count: List[int]) -> List[float]:\n",
    "        def find(i: int) ->int:\n",
    "            t = 0\n",
    "            for k, x in enumerate(count):\n",
    "                t += x\n",
    "                if t >= i:\n",
    "                    return k\n",
    "        mi = 256\n",
    "        mx = 0\n",
    "        cnt = 0\n",
    "        su = 0\n",
    "        mode = 0\n",
    "      \n",
    "      \n",
    "        for k, x in enumerate(count):\n",
    "            if x:\n",
    "                mi = min(mi, k)  # 计算最小值\n",
    "                mx = max(mi, k)  # 计算最大值\n",
    "                su += k * x  # 计算总和\n",
    "                cnt += x  # 计算总数\n",
    "                if x > count[mode]:\n",
    "                    mode = k\n",
    "        \n",
    "        # 按位与判断奇偶\n",
    "        median = find(cnt //2 + 1) if cnt & 1 else (find(cnt // 2) + find(cnt // 2 + 1)) / 2\n",
    "        return [mi, mx, su / cnt, median, mode]\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sampleStats(self, count: List[int]) -> List[float]:\n",
    "        ans = [0] * 5\n",
    "        ans[0] = next(i for i, n in enumerate(count) if n)  # 最小值\n",
    "        ans[1] = next(255 - i for i, n in enumerate(count[::-1]) if n)  # 最大值\n",
    "        ans[2] = sum(i * n for i, n in enumerate(count)) / (total := sum(count))   # 平均数\n",
    "        \n",
    "        # 中位数\n",
    "        med = total // 2\n",
    "        left = right = None\n",
    "        for i, n in enumerate(count):\n",
    "            if med <= n:\n",
    "                if left:\n",
    "                    right = i\n",
    "                    break\n",
    "                else:\n",
    "                    left = i\n",
    "                    med += 1\n",
    "                    if med <= n:\n",
    "                        right = i\n",
    "                        break\n",
    "            med -= n\n",
    "        ans[3] = right if total & 1 else (left + right) / 2\n",
    "\n",
    "        ans[4] = count.index(max(count))    # 众数\n",
    "        return ans\n",
    "        \n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sampleStats(self, count: List[int]) -> List[float]:\n",
    "        n = len(count)\n",
    "        total = sum(count)\n",
    "        mean = 0.0\n",
    "        median = 0.0\n",
    "        min_num = 256\n",
    "        max_num = 0\n",
    "        mode = 0\n",
    "\n",
    "        left = (total + 1) // 2\n",
    "        right = (total + 2) // 2\n",
    "        cnt = 0\n",
    "        max_freq = 0\n",
    "        sum_ = 0\n",
    "        for i,val in enumerate(count):\n",
    "            sum_ += val * i\n",
    "            if val > max_freq:\n",
    "                max_freq = val\n",
    "                mode = i\n",
    "            if val > 0:\n",
    "                if min_num == 256:\n",
    "                    min_num = i\n",
    "                max_num = i\n",
    "            if cnt < right and cnt + val >= right:\n",
    "                median += i\n",
    "            if cnt < left and cnt + val >= left:\n",
    "                median += i\n",
    "            cnt += val\n",
    "        mean = sum_ / total\n",
    "        median = median / 2.0\n",
    "        return [min_num, max_num, mean, median, mode]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\r\n",
    "    def sampleStats(self, count: List[int]) -> List[float]:\r\n",
    "        total=0\r\n",
    "        minimum=-1\r\n",
    "        maximum=-1\r\n",
    "        total=0\r\n",
    "        totalnum=sum(count)\r\n",
    "        if totalnum%2:\r\n",
    "            target1=totalnum//2+1\r\n",
    "            target2=totalnum//2+1\r\n",
    "        else:\r\n",
    "            target1=totalnum//2\r\n",
    "            target2=totalnum//2+1\r\n",
    "        currentnum=0\r\n",
    "        maxcount=0\r\n",
    "        mode=-1\r\n",
    "        median=-1\r\n",
    "        for i in range(len(count)):\r\n",
    "            if count[i]>0:\r\n",
    "                if minimum==-1:\r\n",
    "                    minimum=float(i)\r\n",
    "                maximum=float(i)\r\n",
    "                total=total+i*count[i]\r\n",
    "                if currentnum<target1<=currentnum+count[i]:\r\n",
    "                    targetnum1=float(i)\r\n",
    "                if currentnum<target2<=currentnum+count[i]:\r\n",
    "                    targetnum2=float(i)\r\n",
    "                currentnum+=count[i]\r\n",
    "                if count[i]>maxcount:\r\n",
    "                    mode=float(i)\r\n",
    "                    maxcount=count[i]\r\n",
    "        mean=total/totalnum\r\n",
    "        median=(targetnum1+targetnum2)/2\r\n",
    "        print(targetnum1,targetnum2)\r\n",
    "        return [minimum,maximum,mean,median,mode]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sampleStats(self, count: List[int]) -> List[float]:\n",
    "        n = 0\n",
    "        minimum = 256\n",
    "        maximum = -1\n",
    "        mode = -1\n",
    "        maxcnt = 0\n",
    "        suminum = 0\n",
    "        nums = [0]*256\n",
    "        for num in range(0,256):\n",
    "            if(count[num] == 0):\n",
    "                continue\n",
    "            n += count[num]\n",
    "            minimum = min(minimum, num)\n",
    "            maximum = max(maximum, num)\n",
    "            suminum += num*count[num]\n",
    "            if(count[num] > maxcnt):\n",
    "                maxcnt = count[num]\n",
    "                mode = num\n",
    "        mean = suminum / n \n",
    "        if(n % 2 == 0):\n",
    "            idx1, idx2 = n // 2 - 1, n // 2\n",
    "            cnt = 0\n",
    "            pre = -1\n",
    "            for num in range(0,256):\n",
    "                if(count[num] == 0):\n",
    "                    continue\n",
    "                if(cnt <= idx1 and idx2 < cnt+count[num]):\n",
    "                    median = num\n",
    "                    break\n",
    "                elif(idx1 < cnt and idx2 < cnt+count[num]):\n",
    "                    median = (pre+num)/2\n",
    "                    break\n",
    "                else:\n",
    "                    pre = num \n",
    "                    cnt += count[num]\n",
    "        else:\n",
    "            idx = n // 2\n",
    "            cnt = 0\n",
    "            for num in range(0,256):\n",
    "                if(count[num] == 0):\n",
    "                    continue\n",
    "                if(cnt <= idx and cnt + count[num] > idx):\n",
    "                    median = num \n",
    "                    break\n",
    "                else:\n",
    "                    cnt += count[num]\n",
    "        return [minimum, maximum, mean, median, mode]\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sampleStats(self, count: List[int]) -> List[float]:\n",
    "        mininum, maxinum, sum, n, m, mode = 256, -1, 0, 0, 0, 0\n",
    "        for idx, val in enumerate(count):\n",
    "            if val == 0:\n",
    "                continue\n",
    "            if idx < mininum:\n",
    "                mininum = idx\n",
    "            if idx > maxinum:\n",
    "                maxinum = idx\n",
    "            n += val\n",
    "            sum += idx * val\n",
    "            if val > m:\n",
    "                mode = idx\n",
    "                m = val\n",
    "\n",
    "        mean = sum / n\n",
    "        medianCount = n // 2\n",
    "        medianLeft, medianRight = 0, 0\n",
    "        for idx, val in enumerate(count):\n",
    "            if val == 0:\n",
    "                continue\n",
    "            if medianCount - val == 0:\n",
    "                medianLeft = idx\n",
    "                for j in range(idx + 1, 256):\n",
    "                    if count[j] != 0:\n",
    "                        medianRight = j\n",
    "                        break\n",
    "                break\n",
    "            elif medianCount - val < 0:\n",
    "                medianLeft = medianRight = idx\n",
    "                break\n",
    "            medianCount -= val\n",
    "        if n % 2 == 0:\n",
    "            median = (medianLeft + medianRight) / 2\n",
    "        else:\n",
    "            median = medianRight\n",
    "\n",
    "        return [mininum, maxinum, mean, median, mode]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sampleStats(self, count: List[int]) -> List[float]:\n",
    "        s = 0\n",
    "        total = sum(count)\n",
    "        mode = 0.0\n",
    "        min_num = 256.0\n",
    "        max_num = 0.0\n",
    "        median = 0\n",
    "        left = (total - 1) // 2\n",
    "        right = total // 2\n",
    "        cnt = 0\n",
    "        m = 0\n",
    "        for i in range(256):\n",
    "            if count[i] != 0:\n",
    "                min_num = min(min_num, i)\n",
    "                max_num = max(max_num, i)\n",
    "                s += count[i] * i\n",
    "                if count[i] > m:\n",
    "                    m = count[i]\n",
    "                    mode = i\n",
    "                if cnt <= right and cnt + count[i] > right:\n",
    "                    median += i\n",
    "                if cnt <= left and cnt + count[i] > left:\n",
    "                    median += i\n",
    "                cnt += count[i]\n",
    "\n",
    "        mean = s / total\n",
    "        median = median / 2\n",
    "        return [min_num, max_num, mean, median, mode]\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sampleStats(self, count: List[int]) -> List[float]:\n",
    "        n = 0\n",
    "        minimum = 256\n",
    "        maximum = -1\n",
    "        mode = -1\n",
    "        maxcnt = 0\n",
    "        suminum = 0\n",
    "        nums = [0]*256\n",
    "        for num in range(0,256):\n",
    "            if(count[num] == 0):\n",
    "                continue\n",
    "            n += count[num]\n",
    "            minimum = min(minimum, num)\n",
    "            maximum = max(maximum, num)\n",
    "            suminum += num*count[num]\n",
    "            if(count[num] > maxcnt):\n",
    "                maxcnt = count[num]\n",
    "                mode = num\n",
    "        mean = suminum / n \n",
    "        if(n % 2 == 0):\n",
    "            idx1, idx2 = n // 2 - 1, n // 2\n",
    "            cnt = 0\n",
    "            pre = -1\n",
    "            for num in range(0,256):\n",
    "                if(count[num] == 0):\n",
    "                    continue\n",
    "                if(cnt <= idx1 and idx2 < cnt+count[num]):\n",
    "                    median = num\n",
    "                    break\n",
    "                elif(idx1 < cnt and idx2 < cnt+count[num]):\n",
    "                    median = (pre+num)/2\n",
    "                    break\n",
    "                else:\n",
    "                    pre = num \n",
    "                    cnt += count[num]\n",
    "        else:\n",
    "            idx = n // 2\n",
    "            cnt = 0\n",
    "            for num in range(0,256):\n",
    "                if(count[num] == 0):\n",
    "                    continue\n",
    "                if(cnt <= idx and cnt + count[num] > idx):\n",
    "                    median = num \n",
    "                    break\n",
    "                else:\n",
    "                    cnt += count[num]\n",
    "        return [minimum, maximum, mean, median, mode]\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sampleStats(self, count: List[int]) -> List[float]:\n",
    "        _s=0\n",
    "        num_elmts = 0\n",
    "        minval,maxval=1000,-1\n",
    "        maxfreq=0\n",
    "        imaxfreq=-1\n",
    "        val_cnt = []\n",
    "        for i,c in enumerate(count):\n",
    "            if c!=0:\n",
    "                num_elmts +=c\n",
    "                _s += c*i\n",
    "                if i<minval:\n",
    "                    minval=i\n",
    "                if i>maxval:\n",
    "                    maxval=i\n",
    "                if c>maxfreq:\n",
    "                    maxfreq=c\n",
    "                    imaxfreq=i\n",
    "                val_cnt.append([i,c])\n",
    "\n",
    "        left,right = 0,len(val_cnt)-1\n",
    "        med=-1\n",
    "        while left<=right:\n",
    "            left_val,left_cnt=val_cnt[left]\n",
    "            right_val,right_cnt=val_cnt[right]\n",
    "            if left == right:\n",
    "                med=left_val\n",
    "                break\n",
    "            elif left +1==right:\n",
    "                if left_cnt==right_cnt:\n",
    "                    med=(left_val +right_val)/2.0\n",
    "                    break\n",
    "                elif left_cnt >right_cnt:\n",
    "                    med =left_val\n",
    "                    break\n",
    "                else:\n",
    "                    med=right_val\n",
    "                    break\n",
    "\n",
    "            if left_cnt==right_cnt:\n",
    "                left+=1\n",
    "                right-=1\n",
    "            elif left_cnt>right_cnt:\n",
    "                val_cnt[left][1]-=right_cnt\n",
    "                right-=1\n",
    "            else:\n",
    "                val_cnt[right][1]-=left_cnt\n",
    "                left+=1\n",
    "\n",
    "        return [minval,maxval,_s/num_elmts,med,imaxfreq]\n",
    "\n",
    "            \n",
    "\n",
    "\n",
    "    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sampleStats(self, count: List[int]) -> List[float]:\n",
    "        n = len(count)\n",
    "        total = sum(count)\n",
    "        mean = 0.0\n",
    "        median = 0.0\n",
    "        min_num = 256\n",
    "        max_num = 0\n",
    "        mode = 0\n",
    "\n",
    "        left = (total + 1) // 2\n",
    "        right = (total + 2) // 2\n",
    "        cnt = 0\n",
    "        max_freq = 0\n",
    "        sum_ = 0\n",
    "        for i in range(n):\n",
    "            sum_ += count[i] * i\n",
    "            if count[i] > max_freq:\n",
    "                max_freq = count[i]\n",
    "                mode = i\n",
    "            if count[i] > 0:\n",
    "                if min_num == 256:\n",
    "                    min_num = i\n",
    "                max_num = i\n",
    "            if cnt < right and cnt + count[i] >= right:\n",
    "                median += i\n",
    "            if cnt < left and cnt + count[i] >= left:\n",
    "                median += i\n",
    "            cnt += count[i]\n",
    "        mean = sum_ / total\n",
    "        median = median / 2.0\n",
    "        return [min_num, max_num, mean, median, mode]\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sampleStats(self, count: List[int]) -> List[float]:\n",
    "        s = 0\n",
    "        total = sum(count)\n",
    "        mode = 0.0\n",
    "        min_num = 256.0\n",
    "        max_num = 0.0\n",
    "        median = 0\n",
    "        left = (total - 1) // 2 + 1\n",
    "        right = total // 2 + 1\n",
    "        cnt = 0\n",
    "        m = 0\n",
    "        for i in range(256):\n",
    "            if count[i] != 0:\n",
    "                min_num = min(min_num, i)\n",
    "                max_num = max(max_num, i)\n",
    "                s += count[i] * i\n",
    "                if count[i] > m:\n",
    "                    m = count[i]\n",
    "                    mode = i\n",
    "                if cnt < right and cnt + count[i] >= right:\n",
    "                    median += i\n",
    "                if cnt < left and cnt + count[i] >= left:\n",
    "                    median += i\n",
    "                cnt += count[i]\n",
    "\n",
    "        mean = s / total\n",
    "        median = median / 2\n",
    "        return [min_num, max_num, mean, median, mode]\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sampleStats(self, count: List[int]) -> List[float]:\n",
    "        n = len(count)\n",
    "        total = sum(count)\n",
    "        mean = 0.0\n",
    "        median = 0.0\n",
    "        min_num = 256\n",
    "        max_num = 0\n",
    "        mode = 0\n",
    "\n",
    "        left = (total + 1) // 2\n",
    "        right = (total + 2) // 2\n",
    "        cnt = 0\n",
    "        max_freq = 0\n",
    "        sum_ = 0\n",
    "        for i in range(n):\n",
    "            sum_ += count[i] * i\n",
    "            if count[i] > max_freq:\n",
    "                max_freq = count[i]\n",
    "                mode = i\n",
    "            if count[i] > 0:\n",
    "                if min_num == 256:\n",
    "                    min_num = i\n",
    "                max_num = i\n",
    "            if cnt < right and cnt + count[i] >= right:\n",
    "                median += i\n",
    "            if cnt < left and cnt + count[i] >= left:\n",
    "                median += i\n",
    "            cnt += count[i]\n",
    "        mean = sum_ / total\n",
    "        median = median / 2.0\n",
    "        return [min_num, max_num, mean, median, mode]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sampleStats(self, count: List[int]) -> List[float]:\n",
    "        max_num = -1\n",
    "        min_num = 300\n",
    "        mean = 0\n",
    "        median = 0\n",
    "        sums = 0\n",
    "        n = 0 \n",
    "        mode = 0\n",
    "        max_mode = count[0]\n",
    "        for i in range(len(count)):\n",
    "            if max_mode<count[i]:\n",
    "                mode = i\n",
    "                max_mode = count[i]\n",
    "            if min_num==300 and count[i]>0:\n",
    "                min_num=float(i)\n",
    "            if count[i]>0:\n",
    "                max_num = float(i)\n",
    "            sums+=i*count[i]\n",
    "            n+=count[i]\n",
    "        mean = sums/n\n",
    "        if n%2==0:\n",
    "            l,r = n//2,n//2+1\n",
    "            cur_n = 0\n",
    "            left = -1\n",
    "            right = -1\n",
    "            for i in range(len(count)):\n",
    "                cur_n+=count[i]\n",
    "                if cur_n>=r:\n",
    "                    if left == -1 and right == -1:\n",
    "                        left = i\n",
    "                        right = i\n",
    "                    elif left!=-1 and right == -1:\n",
    "                        right = i\n",
    "                    break\n",
    "                elif cur_n>=l and cur_n<r:\n",
    "                    if left ==-1:\n",
    "                        left = i\n",
    "            median=(left+right)/2\n",
    "        else:\n",
    "            mid = n//2+1\n",
    "            midd = -1\n",
    "            cur_n = 0\n",
    "            for i in range(len(count)):\n",
    "                cur_n+=count[i]\n",
    "                if  midd== -1 and cur_n>=mid:\n",
    "                    median=float(i)\n",
    "                    break\n",
    "        return [min_num,max_num,mean,median,float(mode)]\n",
    "            \n",
    "                    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sampleStats(self, count: List[int]) -> List[float]:\n",
    "        minimum, maximum, mean, median, mode = -1, 0, 0, 0, 0\n",
    "        freq = 0\n",
    "        total = 0\n",
    "        n = 0\n",
    "        for i, c in enumerate(count):\n",
    "            if c == 0:\n",
    "                continue\n",
    "\n",
    "            n += c\n",
    "            total += i * c\n",
    "\n",
    "            if minimum == -1:\n",
    "                minimum = i\n",
    "            maximum = i\n",
    "\n",
    "            if c > freq:\n",
    "                freq = c\n",
    "                mode = i\n",
    "            \n",
    "            count[i] = n\n",
    "        \n",
    "        mean = total / n\n",
    "\n",
    "        first = -1\n",
    "        half = n // 2\n",
    "        \n",
    "        for i, c in enumerate(count):\n",
    "            if c == half:\n",
    "                if n % 2 == 0:\n",
    "                    first = i\n",
    "                continue\n",
    "    \n",
    "            if c >= half:\n",
    "                print(i, c, n % 2, half, first)\n",
    "                # if n % 2:\n",
    "                #     median = i\n",
    "                #     break\n",
    "                \n",
    "                if first >= 0:\n",
    "                    median = (first + i) / 2\n",
    "                else:\n",
    "                    median = i\n",
    "\n",
    "                break\n",
    "                \n",
    "\n",
    "        \n",
    "\n",
    "        return [minimum, maximum, mean, median, mode]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sampleStats(self, count: List[int]) -> List[float]:\n",
    "        mn = mx = -1\n",
    "        totsum, totcnt = 0, sum(count)\n",
    "        mode = maxv = med = cnt = 0\n",
    "        n = len(count)\n",
    "        left, right = (totcnt + 1) // 2, (totcnt + 2) // 2\n",
    "\n",
    "        for i, x in enumerate(count):\n",
    "            if x:\n",
    "                if mn == -1: mn = i \n",
    "                mx = i \n",
    "                totsum += x * i \n",
    "                if x > maxv:\n",
    "                    maxv = x\n",
    "                    mode = i\n",
    "                if cnt < right and cnt + x >= right:\n",
    "                    med += i \n",
    "                if cnt < left and cnt + x >= left:\n",
    "                    med += i \n",
    "                cnt += x\n",
    "        \n",
    "        return [mn, mx, totsum/totcnt, med/2, mode]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sampleStats(self, count: List[int]) -> List[float]:\n",
    "        n = len(count)\n",
    "        total = sum(count)\n",
    "        mean = 0.0\n",
    "        median = 0.0\n",
    "        min_num = 256\n",
    "        max_num = 0\n",
    "        mode = 0\n",
    "\n",
    "        left = (total + 1) // 2\n",
    "        right = (total + 2) // 2\n",
    "        cnt = 0\n",
    "        max_freq = 0\n",
    "        sum_ = 0\n",
    "        for i in range(n):\n",
    "            sum_ += count[i] * i\n",
    "            if count[i] > max_freq:\n",
    "                max_freq = count[i]\n",
    "                mode = i\n",
    "            if count[i] > 0:\n",
    "                if min_num == 256:\n",
    "                    min_num = i\n",
    "                max_num = i\n",
    "            if cnt < right and cnt + count[i] >= right:\n",
    "                median += i\n",
    "            if cnt < left and cnt + count[i] >= left:\n",
    "                median += i\n",
    "            cnt += count[i]\n",
    "        mean = sum_ / total\n",
    "        median = median / 2.0\n",
    "        return [min_num, max_num, mean, median, mode]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sampleStats(self, count: List[int]) -> List[float]:\n",
    "        i=0\n",
    "        min=255\n",
    "        max=0\n",
    "        mean=0\n",
    "        median=0\n",
    "        mode=0\n",
    "        nmode=0\n",
    "        n=0\n",
    "        sum=0\n",
    "        j=0\n",
    "        m=0\n",
    "        c=[]\n",
    "        #while(count[i]):\n",
    "        for i in range(0,len(count)):\n",
    "            if(count[i]):\n",
    "                if(min>i):\n",
    "                    min=i\n",
    "                max=i\n",
    "                n=n+count[i]\n",
    "                sum=sum+i*count[i]\n",
    "                if(count[i]>nmode):\n",
    "                    mode=i\n",
    "                    nmode=count[i]\n",
    "                \n",
    "                '''for m in range(count[i]):\n",
    "                    c.append(i)\n",
    "                    m+=1\n",
    "                    j+=1'''\n",
    "            i+=1\n",
    "        a=0\n",
    "        b=0\n",
    "        if(n%2==0):\n",
    "            a=n//2\n",
    "            b=a+1\n",
    "        else:\n",
    "            a=b=n//2+1\n",
    "        mean=sum/n\n",
    "        '''a=c[a-1]\n",
    "        b=c[b-1]'''\n",
    "        for j in range(0,len(count)):\n",
    "            if(count[j]):\n",
    "                m=m+count[j]\n",
    "                if(m>=a):\n",
    "                    median+=j\n",
    "                    a=256\n",
    "                if(m>=b):\n",
    "                    median+=j\n",
    "                    break\n",
    "        median=median/2\n",
    "        r:List[float]=[min,max,mean,median,mode]\n",
    "        return r\n",
    "        \n",
    "\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sampleStats(self, count: List[int]) -> List[float]:\n",
    "        n = len(count)\n",
    "        total = sum(count)\n",
    "        mean = 0.0\n",
    "        median = 0.0\n",
    "        min_num = 256\n",
    "        max_num = 0\n",
    "        mode = 0\n",
    "\n",
    "        left = (total + 1) // 2\n",
    "        right = (total + 2) // 2\n",
    "        cnt = 0\n",
    "        max_freq = 0\n",
    "        sum_ = 0\n",
    "        for i in range(n):\n",
    "            sum_ += count[i] * i\n",
    "            if count[i] > max_freq:\n",
    "                max_freq = count[i]\n",
    "                mode = i\n",
    "            if count[i] > 0:\n",
    "                if min_num == 256:\n",
    "                    min_num = i\n",
    "                max_num = i\n",
    "            if cnt < right and cnt + count[i] >= right:\n",
    "                median += i\n",
    "            if cnt < left and cnt + count[i] >= left:\n",
    "                median += i\n",
    "            cnt += count[i]\n",
    "        mean = sum_ / total\n",
    "        median = median / 2.0\n",
    "        return [min_num, max_num, mean, median, mode]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sampleStats(self, count: List[int]) -> List[float]:\n",
    "        n = 256\n",
    "        mp = defaultdict(int)\n",
    "        for i in range(n):\n",
    "            if count[i]: mp[i] = count[i]\n",
    "\n",
    "        mean = sum(k * v for k, v in mp.items()) / sum(mp.values())\n",
    "\n",
    "        tot = sum(mp.values())\n",
    "        cnt = 0\n",
    "        t = sorted(mp.items())\n",
    "        for i, (k, v) in enumerate(t):\n",
    "            cnt += v\n",
    "            if 2 * cnt >= tot:\n",
    "                if tot & 1: median = k\n",
    "                else:\n",
    "                    if cnt == tot // 2: median = (k + t[i + 1][0]) / 2\n",
    "                    else: median = k\n",
    "                break\n",
    "\n",
    "        mode = sorted(mp.items(), key = lambda x: -x[1])[0][0]\n",
    "        return [min(mp), max(mp), mean, median, mode]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sampleStats(self, count: List[int]) -> List[float]:\n",
    "        n = len(count)\n",
    "        total = sum(count)\n",
    "\n",
    "        mean, median, min_num, max_num, mode = 0, 0, 256, 0, 0 \n",
    "        \n",
    "        l = (total+1)//2 \n",
    "        r = (total+2)//2\n",
    "        \n",
    "        cnt = 0 \n",
    "        max_freq = 0 \n",
    "        sum_= 0 \n",
    "\n",
    "        for i in range(n):\n",
    "            sum_ += count[i] * i\n",
    "            if count[i] > max_freq:\n",
    "                max_freq = count[i]\n",
    "                mode = i\n",
    "            \n",
    "            if count[i]>0:\n",
    "                if min_num==256:\n",
    "                    min_num=i \n",
    "                max_num = i\n",
    "            \n",
    "            if cnt<r and cnt+count[i]>=r:\n",
    "                median+=i\n",
    "            \n",
    "            if cnt<l and cnt+count[i]>=l:\n",
    "                median+=i\n",
    "            \n",
    "            cnt+=count[i]\n",
    "        \n",
    "        mean = sum_/total \n",
    "        median/=2.0 \n",
    "\n",
    "        return [min_num, max_num, mean, median, mode]\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sampleStats(self, count: List[int]) -> List[float]:\n",
    "\n",
    "        min_v = sys.maxsize\n",
    "        max_v = float('-inf')\n",
    "        mode = 0\n",
    "        mode_v = 0\n",
    "        total_count = 0\n",
    "        total_val = 0\n",
    "\n",
    "        for i, c in enumerate(count):\n",
    "            if c > 0:\n",
    "                min_v = min(min_v, i)\n",
    "                max_v = max(max_v, i)\n",
    "                if c > mode:\n",
    "                    mode = c\n",
    "                    mode_v = i\n",
    "                total_count += c\n",
    "                total_val += (i * c)\n",
    "                pass\n",
    "\n",
    "            pass\n",
    "        if total_count % 2 == 0:\n",
    "            p1, p2 = (total_count - 1) // 2, total_count // 2\n",
    "            n1 = self.find_i(count,p1)\n",
    "            n2 = self.find_i(count,p2)\n",
    "            median = (n1+n2) / 2\n",
    "            pass\n",
    "        else:\n",
    "            median = self.find_i(count,total_count//2)\n",
    "\n",
    "        result = [min_v, max_v, (total_val) / (total_count), median, mode_v]\n",
    "        return result\n",
    "        pass\n",
    "\n",
    "    def find_i(self, count, target_i):\n",
    "        p = 0\n",
    "        for i, c in enumerate(count):\n",
    "            p += c\n",
    "            if p > target_i:\n",
    "                return i\n",
    "            pass\n",
    "        pass"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def sampleStats(self, count: List[int]) -> List[float]:\n",
    "        n, lst = sum(count), list(accumulate(count))\n",
    "        for minimum in range(256):\n",
    "            if count[minimum] != 0: break\n",
    "        for maximum in range(255, -1, -1):\n",
    "            if count[maximum] != 0: break    \n",
    "        mean = sum(i * c for i, c in enumerate(count)) / n    \n",
    "        median = bisect.bisect_left(lst, (n >> 1) + 1) if n & 1 else (bisect.bisect_left(lst, n >> 1) + bisect.bisect_left(lst, (n >> 1) + 1)) / 2.0\n",
    "        mode = count.index(max(count))\n",
    "        return minimum, maximum, mean, median, mode\n"
   ]
  }
 ],
 "metadata": {},
 "nbformat": 4,
 "nbformat_minor": 2
}
